home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 6191 < prev    next >
Encoding:
Text File  |  1996-08-05  |  3.0 KB  |  72 lines

  1. Path: news.microsoft.com!news
  2. From: a-cnadc@microsoft.com (Dann Corbit)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Do you have ever pass structures?
  5. Date: 23 Feb 1996 01:32:56 GMT
  6. Organization: Microsoft Corporation
  7. Message-ID: <4gj5g8$6d2@news.microsoft.com>
  8. References: <4ge8mi$qjm@srvr1.engin.umich.edu> <312BE9C9.67A2284E@eden.com> <4gie7s$jim@hacgate2.hac.com>
  9. NNTP-Posting-Host: 157.57.171.202
  10. Mime-Version: 1.0
  11. X-Newsreader: WinVN 0.93.14
  12.  
  13. In article <4gie7s$jim@hacgate2.hac.com>, collins@thor.tu.hac.com says...
  14. >
  15. >Shane Sadler (nexus@eden.com) wrote:
  16. >
  17. >: As you know passing an entire structure to a function pushes that
  18. >: structure onto the stack. By passing pointers, you avoid that sort of
  19. >: overhead and your code is more efficient. When I'm writing what Mr.
  20. >: Collins would call "disposable programs," I might just declare my
  21. >  ^^^^^^^
  22. >
  23. >Sounds like an intelligent, rational, good-looking chap.
  24. >
  25. >: structures globally just out of laziness and expediency, but I can't
  26. >: think of a case in which I would pass the whole structure. So my answer
  27. >: would be "no". Of course, someone else may have experience with passing
  28. >: very small structures (one or two elements). There might be some
  29. >: advantage in this, but a "REAL" advantage? I doubt it. Depends on what
  30. >: you mean by "REAL," I guess...
  31. >
  32. >: -- Shane
  33. >
  34. >
  35. >About the only use I can come up with for passing a large structure on the
  36. >stack would be to interface to a routine written in another language.
  37. >Exactly what that language would be, I haven't a clue.  Outside of this,
  38. >the pass-by-value mechanism for a large structure seems like one of those
  39. >interesting little tidbits that is nice to know about, but rarely ever
  40. >used.
  41. >
  42. >Anyone have any examples of using this, where it actually saved time or
  43. >effort over passing a pointer?
  44. >
  45. >
  46. >                        -- Collins --
  47. >                        
  48. >-----
  49. >The views expressed here are mine alone.
  50. >
  51. >Ron Collins/Hughes Aircraft Company/M20,P20/Tucson Az 85706
  52. >rcollins@thor.tu.hac.com        collins@seagull.rtd.com
  53. >ยก----
  54. The reason to pass a struct by value is to preserve the contents,
  55. just like any other variable.  Obviously, a recursive routine with
  56. large structures passed by value would be a disaster, but structures
  57. of small size are not a problem.  Even a large structure might be
  58. passed if not called iteratively.  Imagine a sorting routine where
  59. we have a struct that contains an array of pointers to records.  
  60. We could give an instance of this struct to several competing 
  61. methods which have an internal "race" to see who gets done first. 
  62. We don't want to pass the array address, because the sorts would
  63. write overtop of each other.  It depends on the architecture too.
  64. In an old DOS app, with a 64K stack, passing structures by value
  65. would be foolhardy.  But Windows NT starts with a 1 Meg stack and
  66. grows it as needed.  I admit that I rarely use this feature, but
  67. once in a great while it is useful.
  68. -- 
  69. The opinions expressed in this message are my own personal views 
  70. and do not reflect the official views of Microsoft Corporation.
  71.  
  72.